<template>
  <el-row
    type="flex"
    justify="space-between"
    align="middle"
    style="height: 40px; width: 100%"
  >
    <el-col>
      <b v-if="obj.data.isOt">{{ obj.data.name }}</b>
      <span v-else>{{ obj.data.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <!-- 两个内容 -->
        <el-col>{{ obj.data.manager }}</el-col>
        <el-col>
          <!-- 下拉菜单 element -->
          <el-dropdown>
            <span> 操作<i class="el-icon-arrow-down" /> </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="showFormAdd(obj.data.id,obj.data.pid)">添加子部门</el-dropdown-item>
              <el-dropdown-item v-if="!obj.data.isOt" @click.native="delDepartment">删除子部门</el-dropdown-item>
              <el-dropdown-item v-if="!obj.data.isOt" @click.native="showFormEdit(obj.data.id)">编辑子部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { delDepartmentApi } from '@/api/departments'
export default {
  props: {
    obj: { // 单个部门
      type: Object,
      required: true
    }
  },
  methods: {
    // 删除部门
    async delDepartment() {
      await this.$confirm('是否要删除？')
      await delDepartmentApi(this.obj.data.id)
      // 通知父组件重新渲染
      this.$emit('getDepartment')
    },
    // 显示添加表单
    showFormAdd(id, pid) {
      this.$emit('showFormAdd', id, pid)
    },
    // 显示编辑表单
    showFormEdit(id) {
      this.$emit('showFormEdit', id)
    }
  }
}
</script>

<style>
</style>
